package 强化训练;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class day40发邮件 {
    static int[] arr;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int n = sc.nextInt();
            List<List<Integer>> res = new ArrayList<>();
            List<Integer> path = new ArrayList<>();
            arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = i;
            }
            findway(res,path,0);
            int count = ways(res);
            System.out.println(count);
        }
    }

    //使用这种方法，牛客会内存溢出
    private static void findway(List<List<Integer>> res,List<Integer> path,int index){
        if (path.size() == arr.length){
            List<Integer> tem = new ArrayList<>(path);
            res.add(tem);
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            if (path.contains(arr[i])){
                continue;
            }
            path.add(arr[i]);
            findway(res,path,i);
            path.remove(path.size() - 1);
        }
    }
    private static int ways(List<List<Integer>> res){
        int count = 0;
        for (int i = 0; i < res.size(); i++) {
            List<Integer> list = res.get(i);
            for (int j = 0; j < list.size(); j++) {
                if (list.get(j) != j ){
                    if (j == list.size() - 1) {
                        count++;
                    }
                }else {
                    break;
                }
            }
        }
        return count;
    }

    //时间复杂度为1，空间复杂度为n的错排问题,通过100%
    private static void errorSort(int n){
        long[] arr = new long[21];
        arr[2] = 1;
        arr[3] = 4;
        for(int i = 3 ;i < arr.length ;i++){
            arr[i] = (i-1) * (arr[i-1] + arr[i-2]);
        }
        System.out.println(arr[n]);
    }
}
